﻿
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>权限参数配置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script type="text/html" id="barDemo">
        <a title="编辑" href="javascript:;" lay-event="edit" id="frmEdit"><i class="layui-icon">&#xe642;</i></a>
        <a title="删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>
    </script>
</head>
<body>
    <div class="layui-fluid">
        <div id="bDiv">
        </div>
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="dForm" id="dForm">
                            <div class="layui-form-item">
                                <div class="layui-inline" >
                                    <input type="text" name="pCode" placeholder="权限编码" class="layui-input" id="pCode">
                             
                                </div>
                                <div class="layui-inline" >
                                    <input type="text" name="pName" placeholder="权限名称" class="layui-input" id="pName">
                                </div>
                                <div class="layui-inline">
                                    <select id="pType" name="pType" >
                                        <option value="">按钮类型</option>
                                    </select>
                                </div>
                                    <div class="layui-inline">
                                    <select id="pUse" name="pUse">
                                        <option value="">按钮用途</option>
                                        <option value="web">页面(web)</option>
                                        <option value="oper">非页面(oper)</option>
                                    </select>
                                </div>
                                <div class="layui-inline">
                                    <input type="text" name="pEvent" placeholder="按钮事件" class="layui-input" id="pEvent" style="width:120%;">
                                </div>
                                <div class="layui-inline" style="margin-left:3%">
                                    <input type="text" name="groupCode" placeholder="分组编码" class="layui-input" id="groupCode" style="float:left;">
                                </div>

                                <input type="text" name="pIcon" placeholder="图标编码" class="layui-input" id="pIcon" style="width:16%;float:left;">
                                <input type="text" name="memo" placeholder="备注说明" class="layui-input" id="memo" style="width:58%;float:left;margin-left:1.3%">
                            </div>
                            <input type="hidden" name="id" id="id">
                            <input type="hidden" name="oldCode" id="oldCode">
                        </form>
                    </div>
                    <div class="layui-card-body  layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>
<script src="~/js/framework/commonjs.js"></script>
<script>
    var currPage = 1;//首先默认值为1，防止出错
    var menuCode = "";
    var dUrl = "../System/getDataList?dataType=powers&condition=";

    $(function () {
        menuCode = getUrlVariable("menuCode");
        DictionaryDropDown("pwt", "pType", "");
        BannerData(menuCode, "bDiv");
        loadData();
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                loadData();
            }
        });
        layui.use('form', function () {
            var form = layui.form;
            form.render();
        });
    })
    /**
    数据加载
    **/
    function loadData() {
        var condition=JSON.stringify(FormToJson("dForm"));
        layui.use('table', function () {
            var table = layui.table;
            table.render({
                elem: '#list'
                , cols: [[ //标题栏
                    { field: 'pCode', title: '权限编码', width: 100 }
                    , { field: 'pName', title: '权限名称', width: 130 }
                    , { field: 'pType', title: '权限类型', width: 100 }
                    , { field: 'groupCode', title: '按钮编码', width: 100 }
                    , { field: 'pEvent', title: '按钮事件', width: 130 }
                    , { field: 'pIcon', title: '权限图标', width: 120 }
                    , { field: 'pUse', title: '权限用途', width: 100 }
                    , { field: 'memo', title: '备注说明', width: 190 }
                    , { field: 'right', title: '数据操作', toolbar: '#barDemo', width: 100, fixed: 'right' }
                ]], done: function (res, curr, count) {
                    currPage = curr;
                    TablePowerHide();
                }
                , height: $(document).height() - $('#list').offset().top 
                , url: dUrl + condition
                , skin: 'row' //表格风格
                , even: true
                , page: true //是否显示分页
                , limits: [15, 20, 30]
                , limit: 15 //每页默认显示的数量
                , id: "tData"
            });
            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'del') {
                    layer.confirm('确认要删除该数据？', function (index) {
                        var info = DelData(data.pCode);
                        if (info.result) {
                            obj.del();
                        } else {
                            layer.msg(info.message);
                        }
                        layer.close(index);
                    });
                } else if (obj.event == 'edit') {
                    $.each(data, function (name, value) {
                        if (name == "pType") {
                            $("#" + name + " option[value='" + value + "'] ").attr("selected", true);
                        } else {
                            $("input[ name='" + name + "']").val(value);
                        }
                    });
                    $("input[ name='oldCode']").val(data.pCode);
                    layui.use('form', function () {
                        var form = layui.form;
                        form.render();
                    });
                }


            });

        });
    }


    function SavePowerData() {
        var datas = JSON.stringify(FormToJson("dForm"));
        $.ajax({
            url: "../System/UpdatePowers",
            data: { datas: datas },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("保存成功");
                    clearForm('dForm');
                    loadData();
                } else {
                    layer.msg(rsl.message);
                }
            }
        });

    }
    /**
    删除菜单方法
    **/
    function DelData(pCode) {
        var info = undefined;
        $.ajax({
            url: "../System/DelPowerByCode",
            data: { pCode: pCode },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                info = data;
            }
        });
        return info;
    }

</script>